

import 'package:syria_sports/core/utils/show_toast.dart';
import 'package:syria_sports/data/models/error_model.dart';

import '../../core/utils/pref_utils.dart';
import '../apiClient/api_client.dart';
import '../apiClient/api_keys.dart';
import '../models/auth/user.dart';
import '../models/data.dart';
import '../remote/dio_helper.dart';

class CoachesController{
  static Future<Data?> getAllCoaches()async{
    var res = await DioHelper.getData( url: ApiClient.getCoaches, bearerToken: PrefUtils.getToken());

    if(res.statusCode != 200){
      ErrorModel.fromResponse(res);
      return null;
    }
    Data response = Data.fromJson(res.data);
    return response;
  }
  static Future<Data?> getMyCoaches()async{
    var res = await DioHelper.getData(
        url: ApiClient.getMyCoaches,
        bearerToken: PrefUtils.getToken(),
      query: {
        "admins_subscriptions_id":PrefUtils.getAdminsSubscriptionsId(),
      }
    );

    if(res.statusCode != 200){
      ErrorModel.fromResponse(res);
      return null;
    }
    Data response = Data.fromJson(res.data);
    return response;
  }
  static Future<Data?> getPublicCoaches()async{
    var res = await DioHelper.getData( url: ApiClient.getPublicCoaches);

    if(res.statusCode != 200){
      ErrorModel.fromResponse(res);
      return null;
    }
    Data response = Data.fromJson(res.data);
    return response;
  }

  static Future<Data?> addRate({required double value ,required String coachId })async{
    var res = await DioHelper.postData(
      url: ApiClient.rate,
      data: {
        'value': value,
        'coach_id' : coachId,
      },
      bearerToken: PrefUtils.getToken(),
    );

    if(res == null)return null;
    if(res.statusCode != 200){
      ErrorModel.fromResponse(res);
    }else{
      showMessage(res.data[ApiKeys.message]);
    }
    return null;
  }

}